package dao;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import models.cards.CityCard;
import models.cards.ICard;
import models.cards.IPlayerCard;
import models.cards.InfectionCityCard;
import models.cards.PlayerCityCard;
import models.city.City;
import models.desease.Disease;
import models.user.User;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.dao.DataAccessException;

public class Demo {
public static void main(String[] args) {
	ApplicationContext context = 
            new ClassPathXmlApplicationContext("beans.xml");
	UserDAO userDao = (UserDAO) context.getBean("userDao");
//	CityDAO cityDao = (CityDAO) context.getBean("cityDao");
//	DiseaseDAO diseaseDao = (DiseaseDAO) context.getBean("diseaseDao");
//	HashMap<String, Disease> diseases = diseaseDao.getAllDiseases();
//	HashMap<String, City> cities = cityDao.getAllCities(diseases);
//	for (String s : cities.keySet())
//	{
//		System.out.println(cities.get(s));
//	}
//	
//	for (String s : diseases.keySet())
//	{
//		System.out.println(diseases.get(s));
//	}
//	GameDAO dao = new GameDAO();
//	dao.createGameObjects();
//	Game game = Game.getInstance();
//	System.out.println(game.getCities().get("Atlanta"));
	
//	GameDAO gameDao = new GameDAO();
//	gameDao.createGameObjects();
//	for (ICard c : Game.getInstance().getInfectionDeck().getDeck())
//	{
//		if (c instanceof InfectionCityCard) {
//			System.out.println(((InfectionCityCard) c).getName());
//		}
//	}
//	List<City> cities = cityDao.getAllCities();
//	cityDao.updateCitiesNeighbours(cities);
//	for (City c : cities)
//	{
////		System.out.println(c.getNeighbourNames());
//		List<String> neighbourNames = c.getNeighbourNames();
//		for (int i=0; i<neighbourNames.size(); i++)
//		{
//			for (City city : cities)
//			{
//				if (city.getName().equals(neighbourNames.get(i)))
//					c.addNeighbour(city);
//			}
//		}
//		System.out.println(c);
//	
//	try {
//		System.out.println(userDao.areUsernameAndMailFree("username", "usernamee@yahoo.com"));
//	} catch (DataAccessException | SQLException e) {
//		// TODO Auto-generated catch block
//		e.printStackTrace();
//	}
//	userDao.insertUserInDataSource(new User());
//	
//	}

	User user = new User();
	user.setEmail("");
	user.setUsername("dimitargradev");
	user.setPassword("qwerty");
	try {
		System.out.println(userDao.checkUserInDataSource(user));
	} catch (DataAccessException | SQLException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
//static Pattern emailPattern = Pattern.compile("[a-zA-Z0-9[!#$%&'()*+,/\\-_\\.\"]]+@[a-zA-Z0-9[!#$%&'()*+,/\\-_\"]]+\\.[a-zA-Z0-9[!#$%&'()*+,/\\-_\"\\.]]+");
//public static boolean isValidEmail(String email) 
//{       
//    Matcher m = emailPattern.matcher(email);
//        return m.matches();
//}

	public static boolean isValidEmailAddress(String email) {
    String ePattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";
    java.util.regex.Pattern p = java.util.regex.Pattern.compile(ePattern);
    java.util.regex.Matcher m = p.matcher(email);
    return m.matches();
	}

}
